// $Id: fault.c,v 1.1.1.1 2012/02/17 03:45:26 hzheng Exp $

#include <stdlib.h>

#include "log.h"

#include "fault.h"

struct evcpe_fault *evcpe_fault_new(void)
{
	struct evcpe_fault *fault;
	evcpe_debug(__func__, "constructing evcpe_fault");
	if (!(fault = calloc(1, sizeof(struct evcpe_fault)))) {
		evcpe_error(__func__, "failed to calloc evcpe_fault");
		return NULL;
	}
	return fault;
}

void evcpe_fault_free(struct evcpe_fault *fault)
{
	if (!fault) return;
	evcpe_debug(__func__, "destructing evcpe_fault");
	free(fault);
}

const char *evcpe_fault_code_to_str(enum evcpe_fault_code code)
{
	switch (code) {
	case EVCPE_FAULT_NONE:
		return "fault none";
	case EVCPE_ACS_METHOD_NOT_SUPPORTED:
		return "Method not supported";
	case EVCPE_ACS_REQUEST_DENIED:
		return "Request denied";
	case EVCPE_ACS_INTERNAL_ERROR:
		return "Internal error";
	case EVCPE_ACS_INVALID_ARGUMENTS:
		return "Invalid arguments";
	case EVCPE_ACS_RESOUCES_EXCEEDS:
		return "Resources exceeded";
	case EVCPE_ACS_RETRY_REQUEST:
		return "Retry request";
	case EVCPE_CPE_METHOD_NOT_SUPPORTED:
		return "Method not supported";
	case EVCPE_CPE_REQUEST_DENIED:
		return "Request denied";
	case EVCPE_CPE_INTERNAL_ERROR:
		return "Internal error";
	case EVCPE_CPE_INVALID_ARGUMENTS:
		return "Invalid arguments";
	case EVCPE_CPE_RESOUCES_EXCEEDS:
		return "Resources exceeded";
	case EVCPE_CPE_INVALID_PARAM_NAME:
		return "Invalid parameter name";
	case EVCPE_CPE_INVALID_PARAM_TYPE:
		return "Invalid parameter type";
	case EVCPE_CPE_INVALID_PARAM_VALUE:
		return "Invalid parameter value";
	case EVCPE_CPE_NON_WRITABLE_PARAM:
		return "Attempt to set a non-writable parameter";
	case EVCPE_CPE_NOTIFICATION_REQUEST_REJECTED:
		return "Notification request rejected";
	case EVCPE_CPE_DOWNLOAD_FAILURE:
		return "Download failure";
	case EVCPE_CPE_UPLOAD_FAILURE:
		return "Upload failure";
	case EVCPE_CPE_FILE_SERVER_AUTH_FAILURE:
		return "File transfer server authentication failure";
	case EVCPE_CPE_UNSUPPORTED_FILE_TRANSFER_PROTOCOL:
		return "Unsupported protocol for file transfer";
	case EVCPE_CPE_DOWNLOAD_FAILURE_UNABLE_TO_JOIN_MULTICAST:
		return "Download failure: unable to join multicast group";
	case EVCPE_CPE_DOWNLOAD_FAILURE_UNABLE_TO_CONTACT_SERVER:
		return "Download failure: unable to contact file server";
	case EVCPE_CPE_DOWNLOAD_FAILURE_UNABLE_TO_ACCESS_FILE:
		return "Download failure: unable to access file";
	case EVCPE_CPE_DOWNLOAD_FAILURE_UNABLE_TO_COMPLETE:
		return "Download failure: unable to complete download";
	case EVCPE_CPE_DOWNLOAD_FAILURE_FILE_CORRUPTED:
		return "Download failure: file corrupted";
	case EVCPE_CPE_DOWNLOAD_FAILURE_FILE_AUTH_FAILURE:
		return "Download failure: file authentication failure";
	default:
		return "unknown";
	}
}

